package Psy_Admin_Page;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

//首页
public class HomePage extends LoginPage{
    public HomePage dataStatistic(){
        waitForWindow(2000);
        //今日咨询数
        WebElement element1 =  driver.findElement(By.cssSelector("div.el-col-12:nth-child(1)"));
        System.out.println(element1.getText());
        //显示数字 无则为0
        WebElement num1 = driver.findElement(By.cssSelector("div.el-col-12:nth-child(1) > span:nth-child(2)"));
        System.out.println(num1.getText());
        //今日咨询时长
        WebElement element2 = driver.findElement(By.cssSelector("div.el-col-12:nth-child(2)"));
        System.out.println(element2.getText());
        //在线咨询师
        WebElement element3 = driver.findElement(By.cssSelector("div.el-col-8:nth-child(1)"));
        System.out.println(element3.getText());
        //正在进行的咨询
        WebElement element4 = driver.findElement(By.cssSelector(".bottomCard > div:nth-child(2)"));
        System.out.println(element4.getText());
        //在线督导
        WebElement element5 = driver.findElement(By.cssSelector("div.m-t-20:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1)"));
        System.out.println(element5.getText());
        //正在进行的咨询
        WebElement element6 = driver.findElement(By.cssSelector("div.m-t-20:nth-child(2) > div:nth-child(2)"));
        System.out.println(element6.getText());
        //7日统计
        WebElement element7 = driver.findElement(By.cssSelector("#consultingStatisticsChart > div:nth-child(1) > canvas:nth-child(1)"));
        System.out.println(element7.getText());
        //当月咨询排行
        WebElement element8 = driver.findElement(By.cssSelector(".consultingStatistics > div:nth-child(2) > span:nth-child(1)"));
        System.out.println(element8.getText());
        //排行榜
        WebElement element9 = driver.findElement(By.cssSelector(".consultingStatistics > div:nth-child(2) > div:nth-child(2)"));
        System.out.println(element9.getText());
        //当月好评排行
        WebElement element10 = driver.findElement(By.cssSelector(".consultingStatistics > div:nth-child(3) > span:nth-child(1)"));
        System.out.println(element10.getText());
        //好评排行榜
        WebElement element11 = driver.findElement(By.cssSelector(" .consultingStatistics > div:nth-child(3) > div:nth-child(2)"));
        System.out.println(element11.getText());
        return this;
    }

    public HomePage goGuestPage(){
        //成功登录
        success();
        //点击访客管理
        driver.findElement(By.xpath("//span[contains(.,'访客管理')]")).click();
        //延时几秒确保页面加载完毕
        waitForWindow(2000);
        assertThat(driver.getTitle(), is("访客管理"));
        return this;
    }

    public HomePage goSupervisorPage(){
        //成功登录
        success();
        //点击督导管理
        driver.findElement(By.xpath("//span[contains(.,'督导管理')]")).click();
        //延时几秒确保页面加载完毕
        waitForWindow(2000);
        assertThat(driver.getTitle(), is("督导管理"));
        return this;
    }

    public HomePage goConsultantPage(){
        //成功登录
        success();
        //点击咨询师管理
        driver.findElement(By.xpath("//span[contains(.,'咨询师管理')]")).click();
        //延时几秒确保页面加载完毕
        waitForWindow(2000);
        assertThat(driver.getTitle(), is("咨询师管理"));
        return this;
    }

    public HomePage goSchedulePage(){
        //成功登录
        success();
        //点击排班表
        driver.findElement(By.xpath("//span[contains(.,'排班表')]")).click();
        //延时几秒确保页面加载完毕
        waitForWindow(2000);
        assertThat(driver.getTitle(), is("排班表"));
        return this;
    }

    public String dialog(){
        waitForWindow(2000);
        WebElement elementText = driver.findElement(By.cssSelector("div.el-message-box__message"));
        String text = elementText.getText();
        System.out.println(text);
        return text;
    }

    //返回当天值班的咨询师/督导列表
    public String getList(){
        waitForWindow(2000);
        WebElement element = driver.findElement(By.cssSelector(".userList"));
        String info = element.getText();
        return info;
    }

    //检查某日的咨询师/督导列表是否有该用户
    public boolean check(String name){
        if(getList().contains(name)){
            return true;
        }
        return false;
    }

    //退出登录
    public HomePage exit(){
        driver.findElement(By.cssSelector(".userMenuBar")).click();
        waitForWindow(1000);
        driver.findElement(By.cssSelector(".menuActionItem > span:nth-child(2)")).click();
        return this;
    }
}
